package com.cos.lession77.service.impl;

import com.cos.lession77.dao.EmpMapper;
import com.cos.lession77.entity.Emp;
import com.cos.lession77.service.EmpServices;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: COS
 * @time: 2022/10/10 9:25
 * @description:
 */
@Service
@Slf4j
@Transactional
public class EmpServicesImpl implements EmpServices {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public Emp getEmpByEno(Integer eno) {
        if (eno>0) {
            return empMapper.getEmpByEno(eno);
        }
        return null;
    }

    @Override
    public boolean addEmp(Emp emp) {
        if (empMapper.addEmp(emp)>0) {
            return true;
        }
        return false;
    }
    @Override
    public boolean updateEmp(Emp emp) {
        if (empMapper.updateEmp(emp)>0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean delEmp(Integer eno) {
        if (eno>0) {
            if (empMapper.delEmp(eno)>0) {
                return true;
            }
        }
        return false;
    }

    @Override
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    public PageInfo<Emp> getEmpByPage(Integer pageNum, Integer pageSize) {
        log.info("执行分页操作~~~~~~");
        PageHelper.startPage(pageNum, pageSize);
        List<Emp> all = empMapper.getAll();
        PageInfo<Emp> info = new PageInfo<>(all);
        return info;
    }

    @Override
    public List<Emp> getAll() {
        return empMapper.getAll();
    }
}
